<?php
// 操作处理页面
header("content-type:text/html;charset=utf-8");
include_once("conn.php");

//设置默认时区
date_default_timezone_set('PRC');
$now_date = date('Y-m-d H:i:s', time());

$action = $_GET['action'];

// 撤销报销申请
if($action == 'retract'){
    $fix_id = $_GET['fix_id'];
    $sql = "UPDATE tb_fixinfo_request SET fix_status = '-1' WHERE fix_id = '".$fix_id."'";
    if(mysqli_query($conn_DB,$sql)){
        echo "<script>alert('撤销成功！');location='../u-retract-fixinfo.php';</script>";
    }else{
        echo "<script>alert('撤销失败！请重试！');history.go(-1);</script>";
    }
}


//账号注销
if($action == 'revoked'){
    session_start();
    $user_id = $_SESSION["USER"]['u_id'];
    $sql = "SELECT * FROM tb_fixinfo_request WHERE u_id = '".$user_id."' AND fix_status = '0' OR fix_status = '1'";
    $result = mysqli_query($conn_DB,$sql);
    if(mysqli_num_rows($result) > 0){
        echo "<script>alert('您还有未处理的报销申请，请先处理！');history.go(-1);</script>";
    }else{
        $sql_del = "UPDATE tb_user SET u_zh_status = '0', u_revoked = '".$now_date."' WHERE u_id = '".$user_id."'";
        if(mysqli_query($conn_DB,$sql_del)){
            echo "<script>alert('注销成功！即将退出系统！');</script>";
            include_once("logout.php");
        }else{
            echo "<script>alert('注销失败！请重试！');history.go(-1);</script>";
        }
    }
}